﻿/*----------------------------------------------------------------
//Copyright (C) 2012 党明
//文件功能描述：前台用户登录
//创建人：党明
//生成时间：2012/04/24 22:07:00
//----------------------------------------------------------------*/

function Login() {
    $("#btnLogin").attr("disabled", true);
    var userName = $("#txtUserName").val();
    var pwd = $("#txtPwd").val();
    if (userName == "") {
        alert("系统提示：请输入用户名！");
        $("#txtUserName").focus();
        $("#btnLogin").attr("disabled", false);
        return;
    }
    if (pwd == "") {
        alert("系统提示：请输入登录密码！");
        $("#txtPwd").focus();
        $("#btnLogin").attr("disabled", false);
        return;
    }


    var url = "/home/AS/LoginCommon.aspx?Action=Login";
    url += "&tttt=" + Math.random();
    var data = "UserName=" + encodeURI(userName);
    data += "&PassWord=" + pwd;

    data += "&autologin=" + $("#bautoLogin").attr("checked");
    data += "&remberme=" + $("#bremeberMe").attr("checked");
    

    $.ajax(
    {
        type: "POST",
        url: url,
        data: data,
        dataType: "json",
        success: function (ret) {
            if (ret.Result == 1) {
                if (returnurl) {
                    location.href = returnurl;
                }
                else {
                    location.href = "/Home/Default.aspx";
                }
            }
            else {
                alert(ret.Message);
                $("#btnLogin").attr("disabled", false);
            }
        }
    });
}


//为每个页面注册一个事件；
function keydown1(e) {
    var e = window.event ? window.event : e;
    var a = e.srcElement || e.target;
    if (e.keyCode == 13 && a.type != "textarea") {
        $("#btnLogin").click();
        e.cancelBubble = true;
        e.returnValue = false;
    }
}

//页面按钮事件
$(document).ready(function () {
    $("#txtUserName,#txtPwd").bind("keydown", keydown1);
    $("#btnLogin").bind("click", Login);
    $("#btnLogin").css({ cursor: "pointer" });
    $("#btnFindPwd").bind("click", function () {
        window.location.href = "/home/findpwd.aspx?returnurl=" + encodeURI(window.location.href);
    });
});